<!-- 活动管理 -->
<template>
    <div class="rightCenter">
        <div class="listTop">
            <div class="listTopAddBut" @click="addClick()">
                新建活动
            </div>
            <div class="listTopInpBox">
                <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div>
                <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索姓名/手机号 ">
            </div>
        </div>
        <ul class="listUl">
            <li class="listLi fristLI">
                <div class="listDiv listOne">
                    活动编号
                </div>
                <div class="listDiv listTwo">
                    活动名称
                </div>
                <div class="listDiv listThree">
                    开始时间
                </div>
                <div class="listDiv listFour">
                    结束时间
                </div>
                <div class="listDiv listFive">
                    参与人数
                </div>
                <div class="listDiv listSix">
                    业务主
                </div>
                <div class="listDiv listSeven">
                    操作
                </div>
            </li>
            <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
                <div class="listDiv listOne">
                    {{item.id}}
                </div>
                <div class="listDiv listTwo">
                    {{item.name}}
                </div>
                <div class="listDiv listThree">
                    {{item.startTime | baseTimeFun}}
                </div>
                <div class="listDiv listFour">
                    {{item.endTime | baseTimeFun}}
                </div>
                <div class="listDiv listFive fontBule" @click='popupOpenClick(index)'>
                    {{item.participantsCount}}
                </div>
                <div class="listDiv listSix">
                    {{item.ownerId}}
                </div>
                <div class="listDiv listSeven">
                    <div class="buttonBox audit" v-show='item.approval == "0" && item.permission % 7 == 0' @click='checkClick(index)'>
                        审核
                    </div>
                    <div class="buttonBox pass" v-show='item.approval == "1" && item.permission % 7 == 0'>
                        审核通过
                    </div>
                    <div class="buttonBox fail" v-show='item.approval == "2" && item.permission % 7 == 0'>
                        审核失败
                    </div>
                    <div class="buttonBox look" v-show='item.permission % 3 != 0' @click='loogClick(index)'>
                        查看
                    </div>
                    <div class="buttonBox edit" v-show='item.permission % 3 == 0' @click='editClick(index)'>
                        编辑
                    </div>
                    <div class="buttonBox delect"  @click='delectClick(index)'>
                        删除
                    </div>
                </div>
            </li>
        </ul>
        <div class="paging">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
            </el-pagination>
        </div>
        <div class="fixedBox" v-show='popupShow'>
            <div class="popuplistBox rightCenter">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        参与用户列表
                    </div>
                    <div class="popuplistBoxTopBut" @click='chidCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <ul class="listUl popuplistBoxUl">
                    <li class="listLi fristLI">
                        <div class="listDiv listChidOne">
                            序号
                        </div>
                        <div class="listDiv listChidTwo">
                            姓名
                        </div>
                        <div class="listDiv listChidThree">
                            成绩
                        </div>
                        <div class="listDiv listChidFour">
                            奖品
                        </div>
                        <div class="listDiv listChidFive">
                            发放奖品
                        </div>
                    </li>
                    <li class="listLi dataLi" v-for="(item,index) in dataChidList" :class="{grayBack:index % 2 == 1}" :key='index'>
                        <div class="listDiv listChidOne">
                            {{index+1}}
                        </div>
                        <div class="listDiv listChidTwo">
                            {{item.custName}}
                        </div>
                        <div class="listDiv listChidThree">
                            {{item.correctCount}}
                        </div>
                        <div class="listDiv listChidFour">
                            {{item.awardInfo}}
                        </div>
                        <div class="listDiv listChidFive">
                            <div class="buttonBox look" v-if='item.awardStatus == 1' @click='prizeClick()'>
                                发奖
                            </div>
                            <div v-else>
                                已发奖
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
         <!-- 审核弹框 -->
        <div class="fixedBox" v-show='checkShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        请选择需要执行的操作
                    </div>
                    <div class="popuplistBoxTopBut" @click='checkCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='checkPassClick()'>
                        审核通过
                    </div>
                    <div class="popupCheckFail" @click='checkFailClick()'>
                        审核失败
                    </div>
                </div>
            </div>
        </div>
         <!-- 删除弹框 -->
        <div class="fixedBox" v-show='delectBoxShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        确认要删除该角色吗？
                    </div>
                    <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='delectOkClick()'>
                        确 认
                    </div>
                    <div class="popupCheckFail" @click='delectCancelClick()'>
                        取 消
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import taskRequest from "../../assets/task";
export default {
  data() {
    return {
      searchVal: "", //所搜
      dataList: [],
      currentPage: 10, //每页条数
      pageSize: 1, //页码
      totalVal: 0, //总数量
      dataChidList: [],
      popupShow: false, //参与用户弹出框
      checkShow: false,
      delectBoxShow: false,
      editIndex: ""
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "活动管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    } else {
      this.$router.push({
        path: "/login"
      });
      sessionStorage.clear();
      self.$message("暂无权限");
      return;
    }
    self.getList();
  },
  watch: {},
  mounted() {},
  methods: {
    //搜索
    searchFun() {},
    //获取活动列表
    getList() {
      let self = this;
      taskRequest
        .promotionListFun({
          page: self.pageSize,
          size: self.currentPage
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.dataList = data.data.records;
            self.totalVal = data.data.total * 1;
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.currentPage = val;
      this.getList();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageSize = val;
      this.getList();
    },
    //获取参与人数
    getChidList() {},
    //添加
    addClick() {
      this.$router.push({
        path: "/home/activity/edit?button=add"
      });
    },
    //查看
    loogClick(index) {
      this.$router.push({
        path: `/home/activity/look?id=${this.dataList[index].id}`
      });
    },
    //编辑
    editClick() {
      this.$router.push({
        path: `/home/activity/edit?button=edit&id=${this.dataList[index].id}`
      });
    },
    //参与用户点击
    popupOpenClick(index) {
      let self = this;
      if (this.dataList[index].participantsCount) {
        if (this.dataList[index].participantsCount > 0) {
          taskRequest
            .promotionParticipantsFun({
              promotionId: self.dataList[index].id,
              page: 1,
              size: 10000
            })
            .then(data => {
              if (data.statusCode == 200) {
                self.dataChidList = data.data.records;
              } else {
                self.$message(data.statusMessage);
              }
            })
            .catch(msg => {
              self.$message("服务器异常");
            });
          this.popupShow = true;
        }
      }
    },
    //发奖
    prizeClick() {
      let self = this;
      taskRequest
        .promotionDeleteFun({
          promotionId: self.dataList[this.editIndex].id
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.dataChidList = data.data.records;
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.popupShow = false;
    },
    //列表弹框取消
    chidCancelClick() {
      this.popupShow = false;
    },
    //删除
    delectClick(index) {
      this.delectBoxShow = true;
      this.editIndex = index;
    },
    //确认删除
    delectOkClick() {
      let self = this;
      taskRequest
        .promotionDeleteFun({
          id: self.dataList[this.editIndex].id
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.$message({
              showClose: true,
              message: "删除成功",
              type: "success"
            });
            self.getList();
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.delectBoxShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.delectBoxShow = false;
    },
    //审核
    checkClick(index) {
      let self = this;
      this.editIndex = index;
      this.checkShow = true;
    },
    //审核通过
    checkPassClick() {
      let self = this;
      console.log(self.editIndex);
      console.log(self.dataList[self.editIndex]);
      taskRequest
        .promotionUpdateApprovalFun({
          id: self.dataList[self.editIndex].id,
          approval: 1
        })
        .then(data => {
          if (data.statusCode == 200) {
             self.$message({
              showClose: true,
              message: "审核成功",
              type: "success"
            });
            self.getList();
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.checkShow = false;
    },
    //审核失败
    checkFailClick() {
      let self = this;
      taskRequest
        .promotionUpdateApprovalFun({
          id: self.dataList[self.editIndex].id,
          approval: 2
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.$message({
              showClose: true,
              message: "审核失败",
              type: "success"
            });
            self.getList();
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.checkShow = false;
    },
    //取消审核
    checkCancelClick() {
      this.checkShow = false;
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 12%;
}

.listTwo {
  width: 12%;
}

.listThree {
  width: 12%;
}

.listFour {
  width: 12%;
}

.listFive {
  width: 12%;
}

.listSix {
  width: 12%;
}

.listSeven {
  width: 28%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.audit {
  background: #f0a11f;
  margin-right: 4px;
}

.pass {
  color: #33ba78;
  margin-right: 4px;
  cursor: no-drop;
}

.fail {
  color: #ed4a47;
  margin-right: 4px;
  cursor: no-drop;
}

.look {
  background: #279de2;
  margin: 0 4px;
}

.edit {
  background: #279de2;
  margin: 0 4px;
}

.delect {
  background: #ed4a47;
  margin-left: 4px;
}

.listChidOne {
  width: 18%;
}

.listChidTwo {
  width: 18%;
}

.listChidThree {
  width: 18%;
}

.listChidFour {
  width: 22%;
}

.listChidFive {
  width: 22%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>